package com.example.com.skills_utf8;

import android.app.Fragment;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.bean.Talk;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.exception.DbException;

import java.util.List;
import java.util.Random;

import service.MyLocalService;


//
public class _68Fragment extends Fragment {


    MyLocalService.MyBinder binder;
    ServiceConnection sc;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View view = inflater.inflate(R.layout.fragment_68, container, false);

        final DbUtils db = DbUtils.create(getActivity());
        final Random random = new Random( System.currentTimeMillis() );

        Button btn_add = (Button)view.findViewById(R.id.btn_add);
        Button btn_check = (Button)view.findViewById(R.id.btn_check);

        btn_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                try {
                    Talk talk = new Talk();
                    talk.setId_user( ""+random.nextInt() );
                    talk.setAddTime("" + System.currentTimeMillis());
                    db.save(talk);


                } catch (DbException e) {
                    e.printStackTrace();
                }


            }
        });
        btn_check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                try {
                    List<Talk> listdata = db.findAll(Talk.class);
                    for(int i =0; i<listdata.size(); i++){
                        Talk talk = listdata.get(i);
                        Log.e("", "id_user: "+talk.getId_user()+"AddTime: "+talk.getAddTime());
                    }

                } catch (DbException e) {
                    e.printStackTrace();
                }

            }
        });


        return view;

    }


    @Override
    public void onDestroy() {
        super.onDestroy();

    }
}
